/**
 *====================================================
 * 文件名称: BaseController.java
 * 修订记录：
 * No    日期				作者(操作:具体内容)
 * 1.    2012-9-21			ulyn(创建:创建文件)
 *====================================================
 * 类描述：Controller的基类
 * 
 */
package com.jmu.bishe.web.common;

import org.apache.log4j.Logger;

import com.jmu.bishe.entity.Member;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

/**
 * <pre>
 * <b><font color="blue">BaseController</font></b>
 * </pre>
 * 
 * <pre>
 * <b>&nbsp;--Controller的基类，主要集成几个常用的方法--</b>
 * </pre>
 * 
 * <pre></pre>
 * 
 * JDK版本：JDK1.5.0
 * 
 * @author <b>ulyn</b>
 */
public class BaseController {

	protected static Logger logger = Logger.getLogger(BaseController.class);

	
	/**
	 * 获取当前用户 
	 * @param request
	 * @return 
	 */
	protected Member getCurUser(HttpServletRequest request) {
		try{
			Member user = (Member) request.getSession().getAttribute("user");
			return user;
		}catch (Exception e) {
			return null;
		}
	}
	
	/**
	 * 输出响应流
	 * @param response
	 * @param content：要输出的内容
	 * @return
	 */
	protected void printOut(HttpServletResponse response, String content) {
		response.setCharacterEncoding("UTF-8");
		PrintWriter writer = null;
		try {
			writer = response.getWriter();
			// response.setContentLength(responseContent.length());
			writer.write(content);
			writer.flush();
			writer.close();
		} catch (Exception e) {
			logger.info("消息输出出错", e);
		} finally {
			if (writer != null) {
				writer.close();
			}
		}
	}
    protected void printOutJSONP(HttpServletResponse response,String callback, String content) {
        printOut(response, callback+"("+content+");");
    }
}
